//import {api, dl} from 'store/types'
import Vue from 'vue';
import * as types from './types'
/*import * as store  from '../../'
console.log(store)*/
const vm = new Vue();
export  default {
    state: {
        deposit: 0,
        orderInfo: {},
        progress: [],
        orderType: '',
        messageType: '',
      mainOrderInfo:[]
    },
    mutations: {
        dlIndex(state, x){
            state.type = x.type
            state.index = x.index
        },
        SET_ORDERTYPE(state, orderType){
            state.orderType = orderType;
        },
        SET_MESSAGETYPE(state, messageType){
            state.messageType = messageType;
        },
        /*[dl.setDeposit] (state, deposit) {
         state.deposit = deposit
         },*/
        SET_ORDERINFO(state, orderInfo){
            state.orderInfo = orderInfo;
        },
        SET_PROGRESS(state, progress){
            state.progress = progress;
        },
        [types.DL_WZRY_ORDERINFO](state,mainOrderInfo){
            if(mainOrderInfo){
                state.mainOrderInfo=mainOrderInfo
            }else{
                state.mainOrderInfo={}
                state.orderInfo={}
            }
        }
    },
    actions: {
        /*[dl.start]({dispatch, state, commit}, params) {
         dispatch(api.getDeposit, params, {root: true}).then(d => {
         commit(dl.setDeposit, d)
         })
         },*/
         del_dlMainOrderInfo({commit}){
            commit(types.DL_WZRY_ORDERINFO,'');
         },
        [types.GET_DL_WZRY_ORDERINFO]({state,commit},params){
            return vm.$http.get(vm.$CONSTANTS.APIdl+'levelingmainorder/getOrderDetail',{params}).then(res=>{
                if(res.body.responseStatus.code=='00'){
                    commit(types.DL_WZRY_ORDERINFO,JSON.parse(res.body.result))
                  return JSON.parse(res.body.result)
                }
            })
        },
        GET_ORDERINFO({commit, state}, orderNum){
            return new Promise((resolve, reject) => {
                vm.$http.get(vm.$CONSTANTS.APIdl + state.orderType + orderNum).then((res) => {
                    //为了避免action传多个参数会undefined的情况，把所有变量装到一个对象里传过去
                    var orderInfo = {};
                    orderInfo.bullyUserInfo = res.body.bullyUserAccountEO;
                    orderInfo.levelingOrder = res.body.levelingOrder;
                    orderInfo.playerUserInfo = res.body.playerUserAccountEO;
                    commit('SET_ORDERINFO', orderInfo);
                    resolve(orderInfo);
                }, (res) => {
                    console.log(res)
                    reject();
                });

            })
        },
        GET_PROGRESS({commit, state}, params){
            return vm.$http.get(vm.$CONSTANTS.APIMessage + 'message/' + state.messageType, {params}).then((res) => {
                commit('SET_PROGRESS', res.body.messageList.reverse())
            }, (res) => {
                console.log(res)
            });
        },
    }
}

